﻿function resizeImage(img,nsize)
{
    $(document).ready(function() {
	    var nWidth=img.width;
	    var	nHeight=img.height;	
	    nScale = nWidth/nHeight;		
	    //Check:
	    if (nScale > 1) {
		    nWidth = nsize;		
		    nHeight = (nWidth*img.height)/img.width;
		    //fix vertical-align:	
		    nMargin = (nWidth - nHeight)/2;
		    //Set style to image:
		    img.width = nWidth;
		    img.height = nHeight;
		    img.style.margin = nMargin + 'px 0px';
		    }
	    else {
		    //Return size:
		    nHeight = nsize;
		    nWidth = (nHeight*img.width)/img.height;
		    //fix align:	
		    nMargin = (nHeight - nWidth)/2;	
		    //Set style to image:	
		    img.width = nWidth;
		    img.height = nHeight;
		    img.style.margin = '0px ' + nMargin + 'px';
	    }	
	    
	});
}

